Advertisement
35657

Untitled

May 18th, 2024
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include <fstream>
  6. #include <Windows.h>
  7.  
  8. using namespace std;
  9.  
  10.  
  11. int main() {
  12.     SetConsoleCP(1251);
  13.     SetConsoleOutputCP(1251);
  14.  
  15.     ifstream fin;
  16.  
  17.     fin.open("file.txt");
  18.  
  19.     if (!fin.is_open()) {
  20.         cout << "Ошибка открытия файла" << endl;
  21.     }
  22.     else {
  23.         char word[40], longest_word[40];
  24.         int size = 0;
  25.  
  26.         while (!fin.eof()) {
  27.             fin >> word;
  28.             if (strlen(word) > size) {
  29.                 strcpy(longest_word, word);
  30.                 size = strlen(word);
  31.             }
  32.         }
  33.  
  34.         fin.close();
  35.         cout << longest_word << endl;
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement